package com.example.zhou.androidmusic;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.zhou.adapter.MusicPagerAdapter;
import com.example.zhou.filehelper.FileHelper;
import com.example.zhou.filehelper.FileToJson;
import com.example.zhou.filehelper.FileUtil;
import com.example.zhou.fragment.AlbumListFragment;
import com.example.zhou.fragment.MusicListFragment;
import com.example.zhou.musichepler.MusicHelper;
import com.example.zhou.musicmodel.MusicBean;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static java.lang.String.format;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabs)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    private MusicListFragment musicListFragment;
    private AlbumListFragment albumListFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        musicListFragment = MusicListFragment.newInstance();
        albumListFragment = AlbumListFragment.newInstance();
        if (viewPager != null) {
            setUpWithViewPager();
        }
        tabLayout.setupWithViewPager(viewPager);
    }


    private void setUpWithViewPager() {
        MusicPagerAdapter adapter = new MusicPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(musicListFragment, "歌曲");
        adapter.addFragment(albumListFragment, "专辑");
        viewPager.setAdapter(adapter);
    }
}
